﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.DB;
using System.Data;
using MaxLeaf.Common;

namespace MaxLeaf.DAL.K3
{
  
    /// <summary>
    ///价格政策dtl
    /// </summary>
    public class ICPrcPlyEntrySpecDAL : BaseDAL
    {
        public ICPrcPlyEntrySpecDAL()
            : base()
        {
            strTableName = "ICPrcPlyEntrySpec";

            strMapKeyFieldName = "";
            strDestRealKeyFieldName = "";

            mblnNeedEditKeyValue = false;
            mblnIsIdentity = true;
            blnMapKeyUseOtherKeyFieldsCond = false;

            
        }
        public override void Update(DBAccess dbOrgCon, DBAccess dbDestCon, string strKeyValue)
        {
             
        }

        public override void Delete(DBAccess dbOrgCon, DBAccess dbDestCon, string strKeyValue)
        {

        }



        internal void UpdateSpec(DBAccess dbOrgCon, DBAccess dbDestCon, DataRow drOrgDtl, DataRow drDestDtl)
        {
            string strUpdateFieldName = "FInterID,FItemID,FRelatedID,FLPriceCuryID,FLowPrice,FCanSell,FLPriceCtrl,FFlag";
            string strSql = @"select  *
                From
                icPrcPlyEntrySpec   where FinterId=@FInterID and FItemID=@FItemID  and FRelatedID=@FRelatedID";
            KeyValuePair<string, IDataParameter[]> kvpOrg = dbOrgCon.CreateCondParam(new Dictionary<string, object> { 
                 { "FinterId", drOrgDtl["FinterId"] }
                 , { "FItemID", drOrgDtl["FItemID"] }
                ,{ "FRelatedID", drOrgDtl["FRelatedID"] } 
            });
            DataTable dtOrgSpec = dbOrgCon.GetDataTable(strSql, kvpOrg.Value);

            strSql = @"delete From
                icPrcPlyEntrySpec   where FinterId=@FInterID and FItemID=@FItemID  and FRelatedID=@FRelatedID";
            KeyValuePair<string, IDataParameter[]> kvpDest = dbDestCon.CreateCondParam(new Dictionary<string, object> { 
                 { "FinterId", drDestDtl["FinterId"] }
                 , { "FItemID", drDestDtl["FItemID"] }
                ,{ "FRelatedID", drDestDtl["FRelatedID"] } 
            });
            dbDestCon.ExecuteSql(strSql, kvpDest.Value);

            string[] arrFieldName = strUpdateFieldName.Split(',');
            foreach (DataRow drOrgSpec in dtOrgSpec.Rows)
            {

                drOrgSpec["FinterId"] = drDestDtl["FinterId"];
                drOrgSpec["FItemID"] = drDestDtl["FItemID"];
                drOrgSpec["FRelatedID"] = drDestDtl["FRelatedID"];

                //add  
                KeyValuePair<string, IDataParameter[]> kvp = dbDestCon.CreateParamSql(strUpdateFieldName, strTableName, drOrgSpec, LogStatus.Add, string.Empty);
                dbDestCon.GetValue(kvp.Key, kvp.Value);
            }

        }
    }
}
